<?php
// Lấy các thông số cần thiết để view được bài test
			$list_questionID 	= $this->data['question_id'];// danh sách id của câu hỏi
			$list_score    		= $this->data['question_score'];// điểm làm bài của user
			$questionPerPage	= $this->data["question_perpage"];
			$answer_of_user 	= isset($this->data['question'])?$this->data['question']:array(); // các câu trả lời của user
			$list_score_in_test_table	= isset($this->data["list_score_in_test_table"])?$this->data["list_score_in_test_table"]:array();// Điểm của câu hỏi được set trong bài test
			$questionPerPage 	= $questionPerPage==0? 1:$questionPerPage;
			$totalQuestion		= count($list_questionID);
			$totalPage			= (int)($totalQuestion/$questionPerPage);
			$totalPage			= $totalQuestion%$questionPerPage==0?$totalPage:($totalPage+1) ;
?>
<?php if (count($this->arrError)>0) echo $this->error($this->arrError); 
else { ?>
<!--<div class="student_wait_before_practice">
<div  class="table-wait-before-dotest">
	<table>
	  <tr>
	    <th>UIT-KHOA HỆ THỐNG THÔNG TIN</th>
	    <th>BÀI THỰC HÀNH </th>
	  </tr>
	  <tr>
	    <td>BÀI THỰC HÀNH </td>
	    <td> MÔN DATABASE</td>
	  </tr>
	  <tr>
	    <td>(Bài thực hành có: <?php // echo $totalPage; ?> trang) </td>
	    <td>Thời gian làm bài: <?php // echo $this->data['duration_test']; ?> phút </td>
	  </tr>
	  <tr>
	  	<td colspan="2"  class="tdEndTableWait">
	  		<input type="button" class="start_practice" onclick="showTodopractice(); return false;">
	  	</td>
	  </tr>  
	</table>
</div>

</div>-->
<div class="title_test_theme-1">
	<p class="title_test_theme">
		Bài tập khuyến nghị tùy chỉnh.
	</p>
</div>
<div class="student_star_todo_practice">
<form action="<?php echo BASE_URL;?>/pagestudent/studentpractice" method="post" id="studentpractice-form">
<input type="hidden" class="hiTimeStartPractice" name="hiTimeStartPractice">
<input type="hidden" class="hiTimeEndPractice" name="hiTimeEndPractice">
<input type="hidden" class="timeStartCalculate" name="timeStartCalculate">
<input type="hidden" class="timeEndCalculate" name="timeEndCalculate">
<?php if($this->result_test=="on"){ ?>
<table>
	<tr>
		<td colspan="3"> 			
		</td>
	</tr>
	<tr>
		<td>Thời gian bắt đầu làm bài:
		</td>
		<td><?php echo $this->data['hiTimeStartPractice']; ?>
		</td>
		
	</tr>
	<tr>
		<td> Thời gian nộp bài:
		</td>
		<td><?php echo $this->data['duration_test']; ?>
		</td>
		
	</tr>
	<tr>
		<td> Tổng thời gian làm bài:
		</td>
		<td> 
		</td>
		
	</tr>
	<tr>
		<td> Số đáp án đúng:
		</td>
		<td> 
		</td>
		
	</tr>
	<tr>
		<td> Điểm:
		</td>
		<td> 
		</td>
		
	</tr>
	<tr>
		<td> Đánh giá đề bài:
		</td>
		<td> 
		</td>
		
	</tr>
	
</table>

<?php } ?>
<?php					
			$link = "<div class='page_review_test'><font style='font-size: 16px; font-weight: bold; '>Trang: </font> ";
			for($i=0;$i<$totalPage;$i++)
				$link .= "&nbsp;<a href='#' onclick='showPage($i,$questionPerPage); return false;'><span class='focus-page-test-1'> ".($i+1)."</span></a> &nbsp;&nbsp;";
			$link .="</div><hr/>";
			echo $link;
			if(!empty($list_questionID[0])){		
				if($this->first_load==0){
					foreach($list_questionID as $key=>$list_questionIDItem){ 
                                            $answer_of_user[$list_questionIDItem] = isset($answer_of_user[$list_questionIDItem])?$answer_of_user[$list_questionIDItem]:"";
                                            $list_score[$key] = isset($list_score[$key])?$list_score[$key]:1;
                                            //$list_score_in_test_table[$key] = isset($list_score_in_test_table[$key])?$list_score_in_test_table[$key]:1;
                                            
                                            // Begin Lấy đường dẫn tuyệt đối cho hình ảnh
                                            $HTML = $this->viewQuestionHasShuffle(isset($this->data["test_id"])?$this->data["test_id"]:null,
                                                    trim($list_questionIDItem),
                                                    "Câu ".($key+1)." : ",
                                                    $answer_of_user[$list_questionIDItem],
                                                    $this->review_test,$this->view_corect,
                                                    $this->view_feedback,
                                                    $this->view_send_result,
                                                    $list_score[$key],
                                                    isset($list_score_in_test_table[$key])?$list_score_in_test_table[$key]:null);
                                            $HTML = Zend_View_Helper_FormatDate::_tinyMce_get_absolute_path_image("../../../media/images/tinymce","http://".$_SERVER['SERVER_NAME'].BASE_URL."/media/images/tinymce" ,$HTML);
							// End lấy đường dẫn tuyệt đối cho hình ảnh
							echo  $HTML;
						
							echo "<span class='separator-question-test'><hr/></span>";
					}
				}

				if($this->first_load==1){
					foreach($list_questionID as $key=>$list_questionIDItem){ 
                                            $answer_of_user_temp = isset($answer_of_user[$list_questionIDItem])?$answer_of_user[$list_questionIDItem]:"";
                                            $list_score_temp = isset($list_score[$key])?$list_score[$key]:1;
							// Begin Lấy đường dẫn tuyệt đối cho hình ảnh
							$HTML = $this->viewQuestionDoTestAgain($this->data["test_id"],
                                                                trim($list_questionIDItem),
                                                                "Câu ".($key+1)." : ",
                                                                $answer_of_user_temp,
                                                                $this->review_test,$this->view_corect,
                                                                $this->view_feedback,$this->view_send_result,
                                                                $list_score_temp,
                                                                $list_score_in_test_table[$key]);
							$HTML = Zend_View_Helper_FormatDate::_tinyMce_get_absolute_path_image("../../../media/images/tinymce","http://".$_SERVER['SERVER_NAME'].BASE_URL."/media/images/tinymce" ,$HTML);
							// End lấy đường dẫn tuyệt đối cho hình ảnh
							echo  $HTML;
						
							echo "<span class='separator-question-test'><hr/></span>";
					}
				}
				
			$link = "<div class='page_review_test'><font style='font-size: 16px; font-weight: bold; '>Trang: </font> ";
				for($i=0;$i<$totalPage;$i++)
					$link .= "&nbsp;<a href='#' onclick='showPage($i,$questionPerPage); return false;'><span class='focus-page-test-2'> ".($i+1)."</span></a> &nbsp;&nbsp;";			
			$link .="</div>";
			echo $link;
			}
?>			
<p align="center">
			<input name="question_perpage" type="hidden" class="question_per_page" value="<?php echo $questionPerPage; ?>">
			<a  class="all-bt-do-test" href="#" onclick="endTest(); return false;">Nộp bài </a>&nbsp;&nbsp;&nbsp;&nbsp;
                        <a  class="all-bt-do-test" href="#" onclick="window.close()">Đóng lại</a>
			
</p>
</form>
<hr/>
</div>
<?php } ?>

<script type="text/javascript" language="javascript">
<!--
$(document).ready(function(){
	$(".divAdsRight").hide();
	$(".student_star_todo_practice").hide();
	$(".question-container-div").hide();
	$(".separator-question-test").hide();
	var question_per_page = $(".question_per_page").val();
	showPage(0,question_per_page);
	$(".focus-page-test").eq(0).addClass("focus-page-test-active");
        showTodopractice();
});


function endTest() {
 	$("#studentpractice-form").submit();
}

function focusPage(up_or_down,currentPage){
	page_obj  = $(".focus-page-test-"+up_or_down);
	page_obj.removeClass("focus-page-test-active");
	page_obj.eq(currentPage).addClass("focus-page-test-active");
}
function showPage(currentPage, questionPerpage)
{
	focusPage(1,currentPage);
	focusPage(2,currentPage);
	$(".question-container-div").hide()
	$(".separator-question-test").hide()
	var start  	= currentPage*questionPerpage;
	var end		= start+questionPerpage;
	for(i=start; i< end; i++){
		$(".separator-question-test").eq(i).show();
		$(".question-container-div").eq(i).show();
	}
}
function showTodopractice(){	
/*
	var currentTime = new Date();
	var year 		= currentTime.getFullYear()+"";
	var month 		= (currentTime.getMonth()+ 1) +"";
	var day 		= currentTime.getDate()+"";
	var hours 		= currentTime.getHours()+"";
	var minutes		= currentTime.getMinutes()+"";
	var seconds		= currentTime.getSeconds()+"";
	
	if (minutes < 10){
		minutes = "0" + minutes
	}
	if(hours > 11)
		am = "PM";
	 else 
		am = "AM";
	
	var dateNow = day + "/" + month + "/" + year + ", " + hours + ":"+minutes + am+seconds;
	$(".hiTimeStartPractice").val(dateNow);
*/
	$(".divAdsRight").show();
	$(".student_star_todo_practice").show();
	//$(".student_wait_before_practice").hide();
	$(".student_wait_before_practice").remove();
		$.ajax({
    				type: "POST",
    				url: $("#BASE_URL").val()+"/index/getstudenttimestart",
    				dataType: "json",
    				success: function(data){
	    				if(data['success']==true){
	    					$(".hiTimeStartPractice").val(data["timeStart"]);
	    					$(".timeStartCalculate").val(data["timeStartCalculate"]);
	    				}else
	    					alert("Có lỗi "+data['error']); 
    				}
				});			
	
	$("#time-countdown").countdown('resume');
}

function beforeStudentSubmit(){
/*
	var currentTime = new Date();
	var year 		= currentTime.getFullYear()+"";
	var month 		= (currentTime.getMonth()+ 1) +"";
	var day 		= currentTime.getDate()+"";
	var hours 		= currentTime.getHours()+"";
	var minutes		= currentTime.getMinutes()+"";
	var seconds		= currentTime.getSeconds()+"";
	
	if (minutes < 10){
		minutes = "0" + minutes
	}
	if(hours > 11)
		am = "PM";
	 else 
		am = "AM";
		
	var dateNow = day + "/" + month + "/" + year + ", " + hours + ":"+minutes + am + seconds;		
	
	$(".hiTimeEndPractice").val(dateNow);
	*/
	
	$("#studentpractice-form").submit();
}

//-->
</script>